﻿@using OBUCare.Web.Infrastructure
@using OBUCare.Core.BL
@using OBUCare.Core.DataAccess;
@{
    ViewBag.Title = "SearchBy";

    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();

    var operatorInfo = UIUtility.GetCurrentUser();

    var menuName = ViewData["menuName"];

    string AgentNo = UIUtility.getAgentByModule(operatorInfo, menuName.ToString());   
}
<link href="../../Content/tableCss.css" rel="stylesheet" type="text/css" />
@using (Html.BeginForm("Search", "Invoice", FormMethod.Post, new { @id = "searchForm" }))
{

    <table>
        <tr>
            <td>
                流水单号：
            </td>
            <td>
                @Html.TextBox("RepairOrderNO", "", new { @style = "width:250px;" })
            </td>
            <td>
            </td>
            <td>
                <input type="button" value="查询" id="btnSearch" />
                @Html.Hidden("searchSql", "", new { @id = "searchSql" })
                 @Html.Hidden("AgentNo",AgentNo, new { @id = "AgentNo" })
            </td>
        </tr>
    </table>
}
<script type="text/javascript">

    $().ready(function () {

        $('#btnSearch').click(function () {
            search();
        });
    });

    function search() {
        //debugger;
        //首先判断该流水单是否已开具发票 如已开具 则进行拦截
        var serialNo = $('#RepairOrderNO').val();
        serialNo = $.trim(serialNo);
        var jdata = { serialNo: serialNo };
        $.post("/Invoice/checkIsExistinfo", jdata,
                        function (data) {
                            if (data.Success == false) {
                                alert(data.ErrorMsg);
                                return false;
                            }
                            else {
                                checkTrue();
                            }
                        });

    }
    function checkTrue() {

        var form = $("#searchForm");
        dataString = form.serialize();
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: dataString,
            cache: false,
            dataType: "json",
            success: function (data) {

                if (data.Success) {
                    //alert('成功');
                    //debugger;
                    var grid = $('#Grid').data('tGrid')
                    $('#searchSql').val(data.Sql)
                    grid.rebind();
                }
                else {
                    alert('失败：' + data.ErrorMsg)
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var err = XMLHttpRequest + "<br />" + textStatus + "<br />" + errorThrown;
                alert(err);
            }
        });
    }
</script>
